package br.com.projeto.task;

import java.io.IOException;

import android.os.Handler;
import android.util.Log;
import br.com.projeto.MegaSenaApplication;
import br.com.projeto.RestClient;
import br.com.projeto.vo.Loteria;

public class SyncJogosTask extends BaseTask<Void, Void, Void>{

	public SyncJogosTask(Handler handler) {
		super(handler);
	}

	@Override
	protected Void doInBackground(Void... params) {
		try {
			Loteria loteria = RestClient.getResultsJsoup();
//			Loteria loteria = RestClient.getResultsJson();
			handler.obtainMessage(MegaSenaApplication.HANDLE_SYNC_OK, loteria).sendToTarget();
//		} catch (JSONException e) {
//			Log.e(TAG, "Erro ao retornar o Json do servidor: ", e);
//			handler.obtainMessage(MegaSenaApplication.HANDLE_SYNC_ERRO_JSON).sendToTarget();
		} catch (IOException e) {
			Log.e(TAG, "Erro ao retornar o Jsoup do servidor: ", e);
			handler.obtainMessage(MegaSenaApplication.HANDLE_SYNC_ERRO_JSOUP).sendToTarget();
		} catch (Exception e) {
			Log.e(TAG, "Erro generio ao consultar o servidor: ", e);
			handler.obtainMessage(MegaSenaApplication.HANDLE_SYNC_ERRO_GENERIC).sendToTarget();
		}
		return null;
	}
}
